#include "libconfigparser.h"
#ifdef _PARSECONFIG_H
#endif


int printElementContent(char *myfile){

  char *file = myfile;
  char *temp;
  xmlTextReaderPtr reader;
  struct service *myservice;

  reader = xmlReaderForFile(file, NULL, 0);

  while(xmlTextReaderRead(reader)){
    switch(xmlTextReaderNodeType(reader)){
      
      case XML_READER_TYPE_ELEMENT:
      if(XML_READER_TYPE_ELEMENT){
        temp = (char *)xmlTextReaderConstName(reader);
        //printf("%s\n", temp); //holds the tags
      }
      
      while(xmlTextReaderMoveToNextAttribute(reader)){
        temp = (char *)xmlTextReaderConstName(reader);
        //printf("%s\n", temp); // Extra tag attributes
        //myservice->name = malloc(sizeof(temp));
        }

      xmlTextReaderMoveToElement(reader);
      continue;
      
    case XML_READER_TYPE_TEXT:
      if( XML_READER_TYPE_TEXT){
        temp = (char *)xmlTextReaderConstValue(reader);
        printf("%s\n", temp);//Tag values
        myservice->name = malloc(strlen(temp));
        free(myservice->name);
      }
      continue;
    }
  }

  }


int main(int argc, char **argv) { 

  char *filename = argv[1];
  xmlTextReaderPtr reader;
  xmlDocPtr doc;
  struct service myservice;

  //myservice.name = "Son name";

  //printf("%s\n", myservice.name);


  if(argc != 2){
    printf("Missing File argument!\n");
    return(0);
  }
  doc = xmlReadFile(filename, NULL, 0);
  
  //printf("%d\n", sizeof(doc));

  //validate 
  if (doc == NULL)
    {
      printf("error: could not parse: %s\n", filename);
    }

  printElementContent(argv[1]);


  xmlFreeTextReader(reader);
  xmlCleanupParser();


  return EXIT_SUCCESS;
}
